def make_averager():
	total = 0
	length = 0
	def averager(value):
		nonlocal total
		nonlocal length
		total += value
		length += 1
		return total/length
	return averager


def coroutine_avg():
	total = 0
	length = 0
	while True:
		try:
			# return total/length
			# yield # 暂停
			# get_value
			value = yield total/length
		except ZeroDivisionError:
			value = yield 0
		print(f"got send value {value}")
		total += value
		length += 1

co_avg = coroutine_avg()
next(co_avg)
print(co_avg.send(1))
print(next(co_avg))
